
Yacon.widget.Marquee = function (conText)
{
	this.flabel 	= "正在交换数据...";
	this.fico   	= "/widget/loading.gif";
	this.isCenter 	= true;
	
	Yacon.apply(this,conText);
	
	this.create();	
}

Yacon.widget.Marquee.Extend(Object,{
	create:function()
	{
		this.element    = document.createElement("SPAN");
		this.element.className = "marquee";
		this.element.style.display = "none";
		this.element.style.position ="absolute";
		this.element.style.zIndex = 999999;
		
		this.img = document.createElement("img");
		this.marquee = document.createElement("marquee");
		this.marquee.isvisible=1;
		this.marquee.scrollamount=3;
		this.marquee.behavior="alternate";
		this.marquee.direction="right";
	
		this.element.appendChild(this.img);
		this.element.appendChild(this.marquee);
		
		document.body.appendChild(this.element);
		
		window.Marquee = this;
		
	},
	setLabel:function(label)
	{
		this.flabel = label;		
	},
	setIco:function(ico)
	{
		this.fico = ico;		
	},
	setCenter:function(isCenter)
	{
		this.isCenter = Yacon.isTrue(isCenter);	
	},
	show:function()
	{
		
		if (!this.element)
			this.create();
		
		if (this.flabel.isEqual(""))
		{
			this.marquee.style.display="none";
		}else
		{
			this.marquee.style.display="";
			this.marquee.innerHTML = this.flabel;
		}
		if (this.fico.isEqual(""))
		{
			this.img.style.display="none";
		}else
		{
			this.img.style.display="";
			this.img.src = contextPath +imgPath+this.fico;
		}
		
		this.element.style.display = "block";
		
		if (this.isCenter)
		{
			posX =(document.body.clientWidth - this.element.offsetWidth) / 2;
			posY =(document.body.clientHeight - this.element.offsetHeight) / 2;
			this._show(posX,posY);		
		}else
		{
			document.body.onmousemove=Yacon.widget.Marquee.envent.onmousemove;
		}
			
	},
	hidden:function()
	{
		if (this.element)
			this.element.style.display="none";
		
		document.body.onmousemove = null;
	},
	_show:function(x,y)
	{
		if (x==0 && y==0) return;

		var posX=document.body.clientWidth + document.body.scrollLeft - this.element.offsetWidth;
		var posY=document.body.clientHeight + document.body.scrollTop - this.element.offsetHeight
			
		posX=(x<posX)?x:posX;
		posY=(y<posY)?y:posY;
		
		this.element.style.left = posX;
		this.element.style.top  = posY;			
	}
});
Yacon.widget.Marquee.envent= 
{
	onmousemove:function()
	{
		if (window.marquee)
			window.marquee._show(event.x+5,event.y+5);
	}
}


Yacon.widget.PageLayer = function()
{
}
Yacon.widget.PageLayer.Extend(Object,{
	
	show:function()
	{
		this.createTemplate();
		if (this.element)
		{
			this.element.style.width   = document.body.clientWidth + document.body.scrollLeft;
			this.element.style.height  = document.body.clientHeight + document.body.scrollTop;
			this.element.style.display = "block";
		}
	},
	showStyle:function(context){
		//页面展示
		this.show();
		//对象
		for(var unit in context)
		{
            if (unit.isEqual("backgroundColor"))
            	this.element.style.backgroundColor = context[unit];
            else  if (unit.isEqual("filter"))
            	this.element.style.filter = context[unit];
            else  if (unit.isEqual("opacity"))
            	this.element.style.opacity = context[unit];
        }
	},
	
	hidden:function()
	{
		if (this.element)
			this.element.style.display = "none";
	},
	createTemplate:function()
	{
		if (!document.all("page_layer"))
		{	
			this.element = document.createElement("DIV");
			this.element.setAttribute("id","page_layer");
			this.element.style.position ="absolute";
			this.element.style.backgroundColor ="white";
			this.element.style.left ="0";
			this.element.style.top ="0";
			this.element.style.zIndex = 99999;
			this.element.style.filter = "alpha(opacity=30)";
			this.element.style.display = "none";
					
			document.body.appendChild(this.element);			
		}else
		{
			this.element =  document.all("page_layer");
		}
	}
})

Yacon.widget.ProBar = function(conText)
{
	this.attach     = document.body;
	this.width      = 500;
	this.proMsg     = "";
	this.proIndex   = 50;
	this.proCount   = 100;	
	this.istoolBar  = true;
	this.swapRate   = 1000;
	this.swapClass  = "";
	this.swapMethod = "";
	
	conText = conText ||{};	
	Yacon.apply(this,conText);
	
}
Yacon.widget.ProBar.Extend(Object,{
	
	show:function()
	{
		this.createTemplate();
		if (this.element)
		{
			this.element.style.display = "block";	
			this.setISToolBar(this.istoolBar);
			this.setWidth(this.width);
			
			if (this.attach == document.body)
			{
				this.element.style.position = "absolute";
				this.element.style.top      = (document.body.clientHeight-this.element.offsetHeight)/2;
				this.element.style.left     = (document.body.clientWidth-this.width)/2;
				if (window.pageLayer) 
					window.pageLayer.show();
			}
			
		}
	},
	setISToolBar:function(toolBar)
	{
		this.istoolBar = Yacon.isTrue(toolBar);
		if (this.istoolBar)
		{
			this.probar_msg.style.display = "block";	
			this.element.style.height ="44px";
		}else
		{
			this.probar_msg.style.display = "none";
			this.element.style.height ="22px";
		}
	},
	setWidth:function(width)
	{
		this.element.style.width = width;
		this.width = this.element.offsetWidth;
	},
	setProMsg:function(proMsg)
	{
		this.proMsg = proMsg;
		if (this.istoolBar && this.probar_msg)
		{
			this.probar_msg.innerText = this.proMsg;
		}
	},
	setproper:function(proIndex,proCount)
	{
		this.proIndex = Yacon.getInt(proIndex);
		this.proCount = Yacon.getInt(proCount);
		
		this.proper = 0;
		if (this.proIndex>0 && this.proCount>0)
		{
			this.proper = (this.proIndex*100)/this.proCount;
			this.probar_per.style.width = this.width*this.proper/100;
			this.probar_per.innerText = this.proper +"%";		
		}
	},
	setSwapRate:function(swapRate)
	{
		this.swapRate = Yacon.getInt(swapRate);
		if(this.swapRate <=0)
			this.swapRate   = 1000;
	},
	setSwapBuss:function(swapClass,swapMethod)
	{
		this.swapClass  = swapClass;
		this.swapMethod  = swapMethod;
	},
	swapData:function()
	{
		this.dataset  = new DataSet();
		this.dataset.setActionName(this.swapClass);
		window.ProBar   = this;
		this.iIntervalID = window.setInterval("ProBar_changeData()",this.swapRate);
	},
	changeData:function()
	{
		this.dataset.switchMessage(this.swapMethod);
		
		if(this.dataset.next())
		{
			this.setProMsg(this.dataset.getFieldValue("promsg"));
			this.setproper(this.dataset.getFieldValue("proIndex"),this.dataset.getFieldValue("proCount"));
			if (this.proper>=100)
			{
				window.clearInterval(this.iIntervalID);
				this.hidden();
			}
		}		
	},
	hidden:function()
	{
		if (this.element)
			this.element.style.display = "none";
		if (window.pageLayer) 
			window.pageLayer.hidden();
	},
	createTemplate:function()
	{
		if (!document.all("probar_element"))
		{	
			this.element = document.createElement("<div id='probar_element' align='center'  style=\"z-index: 999999; filter:alpha(opacity=30);display:none\"></div>") ;
			this.element.innerHTML = "<table  align=\"center\"  cellSpacing=0 style=\"border:1px solid #A1C3E7;width:100%;\" bgcolor=\"#FFFFEC\">" +
					"<tr><td id='probar_msg' bgcolor=\"#A1C3E7\" style=\"font-size:11pt;font-weight: bold;height:22px\"></td></tr>"+
					"<tr><td style=\"height:22px\">	<span class=\"percentBar\" style=\"width:100%;height:22px\">" +
					"<span id='probar_per' class=\"barProgress\" style=\"width:0px;height:20px\"></span></span></td></tr></table>";
			
			this.attach.appendChild(this.element);
		}else
		{
			this.element =  document.all("probar_element");
		}
		this.probar_msg =  document.all("probar_msg");
		this.probar_per =  document.all("probar_per");
	}
})

function ProBar_changeData()
{
	if (window.ProBar)
		window.ProBar.changeData();
}

if (!window.marquee && document.body) 
	window.marquee = new Yacon.widget.Marquee();


if (!window.pageLayer && document.body) 
	window.pageLayer = new Yacon.widget.PageLayer();

